<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/12/28
 * Time: 13:56
 */

namespace Common\Model;


use Think\Model;

class OperationLogModel extends Model
{
    protected $_auto = array(
        array('operation_time', 'time_format', self::MODEL_INSERT, 'function', NOW_TIME ),
        array('user_id',UID),
        array('IP', 'get_client_ip', self::MODEL_INSERT, 'function')
    );

    public function addLog($func, $desc){
        $data['function'] = $func;
        $data['describe'] = $desc;
        $data = $this->token(false)->create($data);
        if(empty($data)){
            return false;
        }
        if (empty($data['log_id'])){
            $id = $this->add();
            if (!$id){
                $this->error = '新增日志出错';
                return false;
            }
            $data['log_id'] = $id;
            return $data;
        }else{
            $this->error = '新增日志出错';
            return false;
        }
    }

}